home *** CD-ROM | disk | FTP | other *** search
- unit Mlrdemo1;
-
- interface
-
- uses
- SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
- Forms, Dialogs, DBTables, Mlrquery, DB, Mlrtable, StdCtrls, Buttons,
- Grids, DBGrids, ExtCtrls, DBCtrls, OgTable, OgQuery, BkMain, OgTools,
- Menus, OgMain, FwdMain, StepMain, Optigrss;
-
- type
- TForm1 = class(TForm)
- bbtnClose: TBitBtn;
- bbtnTable: TBitBtn;
- Label1: TLabel;
- TableSource: TDataSource;
- QuerySource: TDataSource;
- DBGrid1: TDBGrid;
- bbtnQuery: TBitBtn;
- StringGrid1: TStringGrid;
- Label4: TLabel;
- Panel1: TPanel;
- Label2: TLabel;
- Label3: TLabel;
- Label11: TLabel;
- Panel4: TPanel;
- Label5: TLabel;
- Label6: TLabel;
- Label7: TLabel;
- Label8: TLabel;
- Label9: TLabel;
- Label10: TLabel;
- Panel2: TPanel;
- MLRTable1: TMLRTable;
- MLRQuery1: TMLRQuery;
- bbtnOutput: TBitBtn;
- bbtnPlots: TBitBtn;
- ComboBox1: TComboBox;
- MLRTable2: TMLRTable;
- MLRTable3: TMLRTable;
- bbtnOptimize: TBitBtn;
- MLRTable4: TMLRTable;
- Memo1: TMemo;
- DBMemo1: TDBMemo;
- SampleDataSource: TDataSource;
- SampleDataTable: TTable;
- MLRQuery2: TMLRQuery;
- MLRQuery3: TMLRQuery;
- MLRTable5: TMLRTable;
- ComboBox2: TComboBox;
- OptimizeMLR1: TOptimizeMLR;
- BackElimMLR1: TBackElimMLR;
- ComboBox3: TComboBox;
- FwdSelectMLR1: TFwdSelectMLR;
- Table1: TTable;
- MLRQuery4: TMLRQuery;
- StepWiseMLR1: TStepWiseMLR;
- MLRQuery5: TMLRQuery;
- procedure bbtnTableClick(Sender: TObject);
- procedure bbtnQueryClick(Sender: TObject);
- procedure bbtnOutputClick(Sender: TObject);
- procedure bbtnPlotsClick(Sender: TObject);
- procedure ComboBox1Change(Sender: TObject);
- procedure bbtnCloseClick(Sender: TObject);
- procedure Enablebbtn(var bbtn1,bbtn2: TBitBtn);
- procedure bbtnOptimizeClick(Sender: TObject);
- procedure FormActivate(Sender: TObject);
- procedure SelectModelNumber(Sender: TObject);
- procedure ComboBox2DropDown(Sender: TObject);
- procedure FormCreate(Sender: TObject);
- procedure ComboBox3Change(Sender: TObject);
-
- private
- { Private declarations }
- public
- { Public declarations }
- end;
-
- var
- Form1: TForm1;
- Table: TMLRTable;
- Query: TMLRQuery;
-
- QueryModels,TableModels: TMLRModels;
-
- count: integer;
-
- implementation
-
- {$R *.DFM}
-
- procedure TForm1.bbtnTableClick(Sender: TObject);
- var i,j: integer;
- begin
- DBMemo1.Visible := False;
- StringGrid1.Enabled := Table.Active;
- Panel2.Caption := Table.TableName;
- with Table do
- begin
- if Reload then
- begin
- Execute; { perform regression and allow access to results}
- bbtnPlots.Enabled := True;
- bbtnOutput.Enabled := True;
- ComboBox3.Enabled := True;
- bbtnOptimize.Enabled := (ComboBox3.ItemIndex >= 0)
- end; //if Reload
- Label2.Caption := intToStr(n)+' datapoints.';
- Label3.Caption := intToStr(DegreesOfFreedom)+' degrees of freedom.';
- Label11.Caption := intToStr(nControls)+' control variables.';
- StringGrid1.ColCount := nControls + 3;
- StringGrid1.RowCount := n + 7;
- StringGrid1.Cells[1,0] := ResponseVarY.OutputTerm;
- StringGrid1.Cells[0,n+1] := 'Mean';
- StringGrid1.Cells[0,n+2] := 'Std Dev';
- StringGrid1.Cells[0,n+3] := 'Max';
- StringGrid1.Cells[0,n+4] := 'Min';
- StringGrid1.Cells[0,n+5] := 'Parameters';
- StringGrid1.Cells[0,n+6] := 'Constant';
- StringGrid1.Cells[1,n+1] := floatToStrF(yBar,ffFixed,7,3);
- StringGrid1.Cells[1,n+2] := floatToStrF(yStdErr,ffFixed,7,3);
- StringGrid1.Cells[1,n+3] := floatToStrF(yMax,ffFixed,7,3);
- StringGrid1.Cells[1,n+4] := floatToStrF(yMin,ffFixed,7,3);
- StringGrid1.Cells[1,n+5] := '1.00';
- StringGrid1.Cells[2,n+6] := floatToStrF(b[0],ffFixed,7,3);
- for j:= 1 to nControls do
- begin
- StringGrid1.Cells[j+2,0] := cVariable[j].OutputTerm;
- StringGrid1.Cells[j+2,n+1] := floatToStrF(xBar[j],ffFixed,7,3);
- StringGrid1.Cells[j+2,n+2] := floatToStrF(xStdErr[j],ffFixed,7,3);
- StringGrid1.Cells[j+2,n+3] := floatToStrF(xMax[j],ffFixed,7,3);
- StringGrid1.Cells[j+2,n+4] := floatToStrF(xMin[j],ffFixed,7,3);
- StringGrid1.Cells[j+2,n+5] := floatToStrF(b[j],ffFixed,7,3);
- end; { for j := 1}
- for i:= 1 to n do
- begin
- StringGrid1.Cells[0,i] := intToStr(i);
- StringGrid1.Cells[1,i] := floatToStrF(y[i],ffFixed,7,3);
- for j:= 1 to nControls do
- StringGrid1.Cells[j+2,i] := floatToStrF(x[i,j],ffFixed,7,3);
- end { for i := 1}
- end // with Table do
- end;
-
- procedure TForm1.bbtnQueryClick(Sender: TObject);
- var i,j: integer;
- begin
- DBMemo1.Visible := False;
- StringGrid1.Enabled := Query.Active;
- Panel2.Caption := Query.SQL.Strings[0];
- with Query do
- begin
- if ReLoad then
- begin
- Execute;
- bbtnPlots.Enabled := True;
- bbtnOutput.Enabled := True;
- ComboBox3.Enabled := True;
- bbtnOptimize.Enabled := (ComboBox3.ItemIndex >= 0)
- end;
- Label2.Caption := intToStr(n)+' datapoints.';
- Label3.Caption := intToStr(DegreesOfFreedom)+' degrees of freedom.';
- Label11.Caption := intToStr(nControls)+' control variables.';
- StringGrid1.ColCount := nControls + 3;
- StringGrid1.RowCount := n + 6;
- StringGrid1.Cells[1,0] := ResponseVarY.OutputTerm;
- StringGrid1.Cells[0,n+1] := 'Mean';
- StringGrid1.Cells[0,n+2] := 'Std Dev';
- StringGrid1.Cells[0,n+3] := 'Max';
- StringGrid1.Cells[0,n+4] := 'Min';
- StringGrid1.Cells[1,n+1] := floatToStrF(yBar,ffFixed,7,3);
- StringGrid1.Cells[1,n+2] := floatToStrF(yStdErr,ffFixed,7,3);
- StringGrid1.Cells[1,n+3] := floatToStrF(yMax,ffFixed,7,3);
- StringGrid1.Cells[1,n+4] := floatToStrF(yMin,ffFixed,7,3);
- for j:= 1 to nControls do
- begin
- StringGrid1.Cells[j+2,0] := cVariable[j].OutputTerm;
- StringGrid1.Cells[j+2,n+1] := floatToStrF(xBar[j],ffFixed,7,3);
- StringGrid1.Cells[j+2,n+2] := floatToStrF(xStdErr[j],ffFixed,7,3);
- StringGrid1.Cells[j+2,n+3] := floatToStrF(xMax[j],ffFixed,7,3);
- StringGrid1.Cells[j+2,n+4] := floatToStrF(xMin[j],ffFixed,7,3);
- end;
- for i:= 1 to n do
- begin
- StringGrid1.Cells[0,i] := intToStr(i);
- StringGrid1.Cells[1,i] := floatToStrF(y[i],ffFixed,7,3);
- for j:= 1 to nControls do
- StringGrid1.Cells[j+2,i] := floatToStrF(x[i,j],ffFixed,7,3);
- end
- end
- end;
-
- procedure TForm1.bbtnOutputClick(Sender: TObject);
- begin
- if bbtnTable.Enabled then
- Table.Output
- else
- Query.Output
- end;
-
- procedure TForm1.bbtnPlotsClick(Sender: TObject);
- begin
- if bbtnTable.Enabled then
- Table.ShowPlots
- else
- Query.ShowPlots
- end;
-
- procedure TForm1.Enablebbtn(var bbtn1,bbtn2: TBitBtn);
- begin
- bbtn1.Enabled := True;
- bbtn2.Enabled := False
- end;
-
- procedure TForm1.ComboBox1Change(Sender: TObject);
- begin
- bbtnOptimize.Enabled := False;
- bbtnOutput.Enabled := False;
- bbtnPlots.Enabled := False;
- StringGrid1.Enabled := False;
- ComboBox2.Enabled := False;
- with ComboBox1 do
- case ItemIndex of
- 0: begin
- Enablebbtn(bbtnTable,bbtnQuery);
- Table := MLRTable1;
- SetTableModel(TableModels[1],Table);
- end;
- 1: begin
- Enablebbtn(bbtnQuery,bbtnTable);
- Query := MLRQuery1;
- SetQueryModel(QueryModels[1],Query);
- end;
- 2: begin
- Enablebbtn(bbtnTable,bbtnQuery);
- Table := MLRTable2;
- SetTableModel(TableModels[2],Table);
- end;
- 3: begin
- Enablebbtn(bbtnTable,bbtnQuery);
- Table := MLRTable3;
- SetTableModel(TableModels[3],Table);
- end;
- 4: begin
- Enablebbtn(bbtnTable,bbtnQuery);
- Table := MLRTable4;
- SetTableModel(TableModels[4],Table);
- end;
- 5: begin
- Enablebbtn(bbtnQuery,bbtnTable);
- Query := MLRQuery2;
- SetQueryModel(QueryModels[2],Query);
- end;
- 6: begin
- Enablebbtn(bbtnQuery,bbtnTable);
- Query := MLRQuery3;
- SetQueryModel(QueryModels[3],Query);
- end;
- 7: begin
- Enablebbtn(bbtnTable,bbtnQuery);
- Table := MLRTable5;
- SetTableModel(TableModels[5],Table);
- end;
- 8: begin
- Enablebbtn(bbtnQuery,bbtnTable);
- Query := MLRQuery4;
- SetQueryModel(QueryModels[4],Query);
- end;
- 9: begin
- Enablebbtn(bbtnQuery,bbtnTable);
- Query := MLRQuery5;
- SetQueryModel(QueryModels[5],Query);
- end;
- end; { case }
- Memo1.Visible := False;
- DBMemo1.Visible := True;
- SampleDataTable.FindKey([ComboBox1.ItemIndex]);
- Screen.Cursor := crHourGlass;
- if bbtnTable.Enabled then
- begin
- Table.Close;
- Table.DatabaseName := ExtractFilePath(Application.ExeName);
- OptimizeMLR1.Table := Table;
- BackElimMLR1.Table := Table;
- FwdSelectMLR1.Table := Table;
- StepWiseMLR1.Table := Table;
- TableSource.Dataset := Table;
- Table.Open;
- DBGrid1.DataSource := TableSource
- end
- else
- begin
- Query.Close;
- Query.DatabaseName := ExtractFilePath(Application.ExeName);
- OptimizeMLR1.Query := Query;
- BackElimMLR1.Query := Query;
- FwdSelectMLR1.Query := Query;
- StepWiseMLR1.Query := Query;
- QuerySource.Dataset := Query;
- Query.Open;
- DBGrid1.DataSource := QuerySource
- end;
- Screen.Cursor := crDefault;
- end;
-
- procedure TForm1.bbtnCloseClick(Sender: TObject);
- begin
- Close
- end;
-
- procedure TForm1.bbtnOptimizeClick(Sender: TObject);
- begin
- if (pos('Optimal',ComboBox3.Text) > 0) then
- OptimizeMLR1.Run
- else if (pos('Backward',ComboBox3.Text) > 0) then
- BackElimMLR1.Run
- else if (pos('Forward',ComboBox3.Text) > 0) then
- FwdSelectMLR1.Run
- else if (pos('Stepwise',ComboBox3.Text) > 0) then
- StepWiseMLR1.Run;
- if bbtnTable.Enabled then
- bbtnTableClick(Sender);
- if bbtnQuery.Enabled then
- bbtnQueryClick(Sender); {
- msg := 'This project uses a demo version of'+#10#13+
- 'Optigress.'+#10#13+#10#13+
- 'Optigress is a separate product, and'+#10#13+
- 'is NOT included with MLRegress.'+#10#13+#10#13+
- 'Contact Applied Analytic Systems'+#10#13+
- 'for ordering instructions.';
- MessageDlg(msg,mtInformation,[mbOK],0); }
- bbtnOptimize.Enabled := False;
- ComboBox2.Enabled := True;
- DBMemo1.Update
- end;
-
- procedure TForm1.FormActivate(Sender: TObject);
- begin
- SampleDataTable.Close;
- SampleDataTable.DatabaseName := ExtractFilePath(Application.ExeName);
- SampleDataTable.Open;
- end;
-
- procedure TForm1.SelectModelNumber(Sender: TObject);
- var modelno: integer;
- begin
- modelno := 1;
- if (ComboBox2.ItemIndex >= 0) then
- modelno := 1 + ComboBox2.ItemIndex;
- OptimizeMLR1.ModelNumber := modelno;
- if bbtnTable.Enabled then
- bbtnTableClick(Sender);
- if bbtnQuery.Enabled then
- bbtnQueryClick(Sender)
- end;
-
- procedure TForm1.ComboBox2DropDown(Sender: TObject);
- var i: integer;
- begin
- ComboBox2.Items.Clear;
- for i := 1 to OptimizeMLR1.ModelsSaved do
- ComboBox2.Items.Add(intToStr(i))
- end;
-
- procedure TForm1.FormCreate(Sender: TObject);
- begin
- SaveTableModel(TableModels[1],MLRTable1);
- SaveTableModel(TableModels[2],MLRTable2);
- SaveTableModel(TableModels[3],MLRTable3);
- SaveTableModel(TableModels[4],MLRTable4);
- SaveTableModel(TableModels[5],MLRTable5);
- SaveQueryModel(QueryModels[1],MLRQuery1);
- SaveQueryModel(QueryModels[2],MLRQuery2);
- SaveQueryModel(QueryModels[3],MLRQuery3);
- SaveQueryModel(QueryModels[4],MLRQuery4);
- SaveQueryModel(QueryModels[5],MLRQuery5);
- end;
-
- procedure TForm1.ComboBox3Change(Sender: TObject);
- begin
- bbtnOptimize.Enabled := True
- end;
-
-
- end.
-